// pages/addign/addsign.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        courseId:'',
        sname:'',

        beginDate: "2018-09-01",
        beginTime: "00:00",
        endDate: "2018-09-01",
        endTime: "23:59",

        signType:[
            {value:1,name:'复合签到'},
            {value:2,name:'二维码签到'},
            {value:3,name:'定位签到'},
            {value:4,name:'拍照签到'}
            
        ],
        typeIndex:0,
    },

    beginDateChange: function (e) {
        this.setData({
            beginDate: e.detail.value
        })
    },
    beginTimeChange: function (e) {
        this.setData({
            beginTime: e.detail.value
        })
    },
    endDateChange: function (e) {
        this.setData({
            endDate: e.detail.value
        })
    },
    endTimeChange: function (e) {
        this.setData({
            endTime: e.detail.value
        })
    },

    signTypeChange: function (e) {
        this.setData({   
            typeIndex: e.detail.value,
       })
    },

    formSubmit(e) {
        console.log('form发生了fromSubmit事件，携带数据为：', e.detail.value)
        let{courseId,sname,beginDate,beginTime,endDate,endTime,typeIndex} = this.data;
        let postData = {
            courseId:this.data.courseId,
            sname: this.data.sname,
            beginDate: this.data.beginDate,
            beginTime: this.data.beginTime,
            endDate:this.data.endDate,
            endTime:this.data.endTime,
            typeIndex:this.data.typeIndex,
        }
        postData = {...this.data}
        postData = {courseId,sname,beginDate,beginTime,endDate,endTime,typeIndex}

        wx.request({
            url: 'http://localhost/public/sign/sign/addsign',
            method: "POST",
            data: postData,
            success: ({data}) => {
                console.log(data);
                console.log(data.status);
                if(data.status === 'success'){
                    if(data.signType == 0 || data.signType == 1){
                        wx.navigateTo({
                            url: '/pages/qr_code/qr_code?signType='+data.signType,
                        })
                    }else{
                        wx.navigateTo({
                            url: '/pages/signlist/signlist?courseId='+courseId,
                        })
                    }
                }else{
                    this.setData({message:data.message});
                }
            },
            fail:(err)=> {
                console.log(err);
            }
        })
    },
    formReset(e) {
        console.log('form发生了reset事件，携带数据为：', e.detail.value)
        this.setData({
          chosen: ''
        })
    },

    onLoad: function (options) {
        this.setData({
            courseId:options.courseId,
        });
    }
})